﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace QT.SEO
{
    public class Site
    {
        public static DataTable getAll()
        {
            string sql = "select [guid],[sitename],[siteDomain] from [QT_Data_Site] order by [sitename] asc";
            DataTable dt = new QT.DBO.OleDBHelper(myDB.connstring).DataTable(sql);
            return dt;
        }

        public static int Add(string sitename,string sitedomain)
        {
            if (Exsits(null, sitename)) return -2;

            string sql = "insert into [QT_Data_Site]([guid],[sitename],[sitedomain]) values('" + Guid.NewGuid().ToString().Replace("-", "") + "','" + sitename + "','" + sitedomain + "')";
            int rval = new QT.DBO.OleDBHelper(myDB.connstring).ExecuteNonQuery(sql);
            return rval;
        }

        public static int Delete(List<string> guids)
        {
            string sql = "delete from [QT_Data_Site] where [guid] in('" + string.Join("','", guids.ToArray()) + "')";
            int rval = new QT.DBO.OleDBHelper(myDB.connstring).ExecuteNonQuery(sql);
            return rval;
        }

        private static bool Exsits(string guid, string sitename)
        {
            string sql = "select [guid] from [QT_Data_Site] where [sitename]='" + sitename + "'" + (string.IsNullOrEmpty(guid) ? "" : " guid<>'" + guid + "'");
            DataTable dt = new QT.DBO.OleDBHelper(myDB.connstring).DataTable(sql);
            if (dt.Rows.Count > 0) return true;
            else return false;
        }
    }

    public class SiteRecord
    {
    }
}
